package com.gfhd.multithread.service;

public class ThreadDemo2 {
    public void test() {
        Runnable myRunnable = new MyRunnable();
        Thread t = new Thread(myRunnable);
        t.start();
        for (int i = 0; i < 10; i++) {
            System.out.println("主线程执行输出：" + i);
        }
    }

    public void test1() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 20; i++) {
                    System.out.println("子线程执行输出：" + i);
                }
            }
        }).start();
        for (int i = 0; i < 20; i++) {
            System.out.println("主线程执行输出：" + i);
        }
    }

    public void test2() {
        new Thread(() -> {
            for (int i = 0; i < 20; i++) {
                System.out.println("子线程执行输出：" + i);
            }
        }).start();
        for (int i = 0; i < 20; i++) {
            System.out.println("主线程执行输出：" + i);
        }
    }
}
